/**
 * 主题服务
 * 处理应用的主题颜色变更
 */

// 主题配置
const themes = {
  blue: {
    primary: '#007AFF',
    secondary: '#5AC8FA',
    accent: '#4CD964',
    text: '#333333',
    background: '#F8F8F8'
  },
  red: {
    primary: '#FF3B30',
    secondary: '#FF9500',
    accent: '#FFCC00',
    text: '#333333',
    background: '#F8F8F8'
  },
  green: {
    primary: '#4CD964',
    secondary: '#5AC8FA',
    accent: '#007AFF',
    text: '#333333',
    background: '#F8F8F8'
  },
  purple: {
    primary: '#5856D6',
    secondary: '#FF2D55',
    accent: '#5AC8FA',
    text: '#333333',
    background: '#F8F8F8'
  },
  black: {
    primary: '#333333',
    secondary: '#666666',
    accent: '#999999',
    text: '#FFFFFF',
    background: '#222222'
  }
};

// 主题名称到索引的映射
const themeNameToIndex = {
  '蓝色': 0,
  '红色': 1,
  '绿色': 2,
  '紫色': 3,
  '黑色': 4
};

// 索引到主题名称的映射
const themeIndexToName = ['蓝色', '红色', '绿色', '紫色', '黑色'];

// 获取当前主题
const getCurrentTheme = () => {
  try {
    const settings = uni.getStorageSync('metronomeSettings');
    if (settings && typeof settings.themeIndex !== 'undefined') {
      const themeName = themeIndexToName[settings.themeIndex];
      return themes[getThemeKey(themeName)];
    }
    return themes.blue; // 默认主题
  } catch (e) {
    console.error('获取主题设置失败:', e);
    return themes.blue;
  }
};

// 将主题名称转换为主题键
const getThemeKey = (themeName) => {
  switch (themeName) {
    case '蓝色': return 'blue';
    case '红色': return 'red';
    case '绿色': return 'green';
    case '紫色': return 'purple';
    case '黑色': return 'black';
    default: return 'blue';
  }
};

// 应用主题到应用程序
const applyTheme = (themeName) => {
  const themeKey = getThemeKey(themeName);
  const theme = themes[themeKey];
  
  // 这里可以添加更多的主题应用逻辑
  
  return theme;
};

export default {
  themes,
  themeNameToIndex,
  themeIndexToName,
  getCurrentTheme,
  applyTheme,
  getThemeKey
}; 